home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Applications / TCPExample / PNL Libraries / MyStripTelnetCodes.p < prev    next >
Text File  |  1995-06-04  |  792b  |  51 lines

  1. unit MyStripTelnetCodes;
  2.  
  3. interface
  4.  
  5.     const
  6.         T_WILL = chr(251);
  7.         T_WONT = chr(252);
  8.         T_DO = chr(253);
  9.         T_DONT = chr(254);
  10.         T_IAC = chr(255);
  11.  
  12.     procedure StripTelnetCodes (var s: string);
  13.  
  14. implementation
  15.  
  16.     const
  17.         nul = chr(0);
  18.  
  19.     procedure StripTelnetCodes (var s: string);
  20.         var
  21.             i: integer;
  22.     begin
  23.         i := 1;
  24.         while i < length(s) do begin
  25.             case s[i] of
  26.                 T_IAC:  begin
  27.                     case s[i + 1] of
  28.                         T_IAC:  begin
  29.                             Delete(s, i, 1);
  30.                             i := i + 1;
  31.                         end;
  32.                         T_WILL, T_WONT, T_DO, T_DONT:  begin
  33.                             if i < length(s) - 1 then begin
  34.                                 Delete(s, i, 3);
  35.                             end else begin
  36.                                 leave;
  37.                             end;
  38.                         end;
  39.                         otherwise
  40.                             Delete(s, i, 2);
  41.                     end;
  42.                 end;
  43.                 nul: 
  44.                     Delete(s, i, 1);
  45.                 otherwise
  46.                     i := i + 1;
  47.             end;
  48.         end;
  49.     end;
  50.  
  51. end.